
package com.bash.carrep.ui.util;

import com.vaadin.data.Item;
import com.vaadin.data.validator.IntegerValidator;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

/**
 *
 * @author bash
 */
public class CLFieldFactory extends com.bash.carrep.ui.util.PojoFieldFactory {

    public CLFieldFactory() {
    }

    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {

        Field f = super.createField(item, propertyId, uiContext);

        if ("idcreditLevel".equals(propertyId)) {
            TextField tf = (TextField) f;
            tf.setNullRepresentation("");
            tf.setRequired(true);
            tf.setCaption("Code");
            tf.setRequiredError("Veuillez donner un code");
            tf.setWidth("5em");
            tf.addValidator(new IntegerValidator("Le code doit être un entier"));

        } else if ("description".equals(propertyId)) {
            TextField tf = (TextField) f;
            tf.setNullRepresentation("");
            tf.setRequired(true);
            tf.setWidth("15em");
            tf.setRequiredError("Veuillez donner la description");

        }

        return f;
    }
}
